using System;
using UnityEngine;
using QFramework;

namespace ProjectMyFarmAndShe
{
	public partial class UIGameController : ViewController
	{
		public static UIGameController Default;

		private void Awake()
		{
			Default = this;
		}

		void Start()
		{
			// Code Here
			Global.Day.RegisterWithInitValue(day =>
				{
					DayText.text = $"第{day}天";

				})
				.UnRegisterWhenGameObjectDestroyed(gameObject);

			Global.Coin.RegisterWithInitValue(coin =>
				{
					CoinText.text = $"{coin}";

				})
				.UnRegisterWhenGameObjectDestroyed(gameObject);

			Global.OpenPanel.RegisterWithInitValue(openPanel =>
				{
					if (openPanel)
					{
						Global.Mouse.Hide();
					}
					else
					{
						Global.Mouse.Show();
					}

				})
				.UnRegisterWhenGameObjectDestroyed(gameObject);
			
			BtnEmail.onClick.AddListener(() =>
			{
				Global.OpenPanel.Value = true;
				EmailPanel.Show();
			});

			Global.Brawn.RegisterWithInitValue(brawn =>
				{
					BrawnText.text = "体力值:" + brawn.ToString("0.0");
				})
				.UnRegisterWhenGameObjectDestroyed(gameObject);
		}

		public void OpenLevelUpPanel()
		{
			Global.OpenPanel.Value = true;
			LevelUpPanel.Show();
		}

		public void CloseLevelUpPanel()
		{
			Global.OpenPanel.Value = false;
			LevelUpPanel.Hide();
		}

		public void OpenChallengePanel()
		{
			Global.OpenPanel.Value = true;
			ChallengePanel.Show();
		}

		public void CloseChallengePanel()
		{
			Global.OpenPanel.Value = false;
			ChallengePanel.Hide();
		}

		public ShopPanel OpenShopPanel()
		{
			Global.OpenPanel.Value = true;
			ShopPanel.Show();
			return ShopPanel;
		}

		public void CloseShopPanel()
		{
			Global.OpenPanel.Value = false;
			ShopPanel.Hide();
		}

		public DialogPanel OpenDialogPanel()
		{
			Global.OpenPanel.Value = true;
			DialogPanel.Show();
			return DialogPanel;
		}

		public void CloseDialogPanel()
		{
			Global.OpenPanel.Value = false;
			DialogPanel.Hide();
		}

		private void OnDestroy()
		{
			Default = null;
		}
	}
}
